package com.qf.service.impl;

import com.qf.entity.Questions;
import com.qf.mapper.QuestionsMapper;
import com.qf.service.QuestionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @author Administrator
 * @version V1.0
 * @Project spring_AQ
 * @Package com.qf.service.impl
 * @Description: ${TODO}
 * @Date 2021/10/3 23:26
 */

@Service
public class QuestionServiceImpl implements QuestionService {

    @Autowired
    private QuestionsMapper questionsMapper;

    @Override
    @Transactional
    public void insert(Questions question) {
        int i = questionsMapper.insertSelective(question);
        if (i != 1){
            throw new RuntimeException("提问失败");
        }
    }

    @Override
    public Questions findById(Integer id) {
        return questionsMapper.findById(id);
    }

    @Override
    public List<Questions> findAll() {
        return questionsMapper.selectAll();
    }

    @Override
    public void updateById(Questions question) {
        int i = questionsMapper.updateByPrimaryKeySelective(question);
        if (i != 1){
            throw new RuntimeException("问题修改失败");
        }
    }
}
